/*    */ package com.cr.web.controller.system;
/*    */ 
/*    */ import com.cr.common.core.controller.BaseController;
/*    */ import com.cr.common.core.domain.AjaxResult;
/*    */ import com.cr.common.utils.ServletUtils;
/*    */ import org.apache.commons.lang3.StringUtils;
/*    */ import com.cr.framework.web.service.ConfigService;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.apache.shiro.SecurityUtils;
/*    */ import org.apache.shiro.authc.AuthenticationException;
/*    */ import org.apache.shiro.authc.AuthenticationToken;
/*    */ import org.apache.shiro.authc.UsernamePasswordToken;
/*    */ import org.apache.shiro.subject.Subject;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.beans.factory.annotation.Value;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.ui.ModelMap;
/*    */ import org.springframework.web.bind.annotation.GetMapping;
/*    */ import org.springframework.web.bind.annotation.PostMapping;
/*    */ import org.springframework.web.bind.annotation.ResponseBody;
/*    */ 
/*    */ @Controller
/*    */ public class SysLoginController extends BaseController {
/*    */   @Value("${shiro.rememberMe.enabled: false}")
/*    */   private boolean rememberMe;
/*    */   
/*    */   @Autowired
/*    */   private ConfigService configService;
/*    */   
/*    */   @GetMapping({"/login"})
/*    */   public String login(HttpServletRequest request, HttpServletResponse response, ModelMap mmap) {
/* 43 */     if (ServletUtils.isAjaxRequest(request))
/* 45 */       return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}"); 
/* 48 */     mmap.put("isRemembered", Boolean.valueOf(this.rememberMe));
/* 50 */     mmap.put("isAllowRegister", this.configService.getKey("sys.account.registerUser"));
/* 51 */     return "login";
/*    */   }
/*    */   
/*    */   @PostMapping({"/login"})
/*    */   @ResponseBody
/*    */   public AjaxResult ajaxLogin(String username, String password, Boolean rememberMe) {
/* 58 */     UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe.booleanValue());
/* 59 */     Subject subject = SecurityUtils.getSubject();
/*    */     try {
/* 62 */       subject.login((AuthenticationToken)token);
/* 63 */       return success();
/* 65 */     } catch (AuthenticationException e) {
/* 67 */       String msg = "用户或密码错误";
/* 68 */       if (StringUtils.isNotEmpty(e.getMessage()))
/* 70 */         msg = e.getMessage(); 
/* 72 */       return error(msg);
/*    */     } 
/*    */   }
/*    */   
/*    */   @GetMapping({"/unauth"})
/*    */   public String unauth() {
/* 79 */     return "error/unauth";
/*    */   }
/*    */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\classes\com.zip!\com\cr\web\controller\system\SysLoginController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */